<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {

    public function _initRoutes() {
        $front     = Zend_Controller_Front::getInstance();
        $restRoute = new Koncept_Rest_Route($front);
        $front->getRouter()->addRoute('default', $restRoute);
//$router = $ctrl->getRouter(); // returns a rewrite router by default$router->addRoute('user', new Zend_Controller_Router_Route('user/:username', array('controller' => 'user', 'action' => 'info')));
    }

    public function _initRequest() {
        $front     = Zend_Controller_Front::getInstance();
        $front->setRequest($this->request = new Koncept_Rest_Request_Http());
        //echo $this->request->getMethod();
    }

    public function _initResourceLoaders() {

        //define the path as relative
        $path = realpath(APPLICATION_PATH . "/modules/");

        //using the opendir function
        $dir_handle = @opendir($path) or die("Unable to open $path");

        $modules = array(array('basePath' => '/', 'namespace' => ''));
        //running the while loop
        while ($file = readdir($dir_handle)) {
            if(is_dir($fullpath = $path . '/' . $file) && strpos($file, '.') !== 0) {
                $modules[] = array('basePath' => $fullpath, 'namespace' => ucfirst($file));
            }
        }
        //closing the directory
        closedir($dir_handle);

        foreach($modules as $module) {
            $resource = new Zend_Application_Module_Autoloader($module);
        }
        /*
        $resourceLoader = new Zend_Application_Module_Autoloader(array(
                        'basePath'  => APPLICATION_PATH . "/modules/addressbook",
                        'namespace' => 'Addressbook',
        ));

        $resourceLoader = new Zend_Application_Module_Autoloader(array(
                        'basePath'  => APPLICATION_PATH . "/modules/user",
                        'namespace' => 'User',
        ));

        $resourceLoader = new Zend_Application_Module_Autoloader(array(
                        'basePath'  => APPLICATION_PATH . "/modules/cases",
                        'namespace' => 'Cases',
        ));

        $resourceLoader = new Zend_Application_Module_Autoloader(array(
                        'basePath'  => APPLICATION_PATH . "/modules/manage",
                        'namespace' => 'Manage',
        ));

        $resourceLoader = new Zend_Application_Module_Autoloader(array(
                        'basePath'  => APPLICATION_PATH . "/modules/cbmt",
                        'namespace' => 'Cbmt',
        ));

        $resourceLoader = new Zend_Application_Module_Autoloader(array(
                        'basePath'  => APPLICATION_PATH . "/",
                        'namespace' => '',
        ));
         * 
         */
    }



    public function _initInclude() {
        $paths = explode(';', get_include_path());
        foreach($paths as $key => &$path) {
            $path = realpath($path);
        }
        set_include_path(implode(';',array_unique($paths)));
    }
}

